#
# FPC Global Makefile

MODE= NON_PARALLEL


CC = $(COMPILER) $(IDIR) -DBSS -DACEDB -DACEDB_GTK -D$(NAME) -D$(MODE) 


CCFLAGS =   ## to undefine any rubbish
GCFLAGS =   ## to undefine any rubbish

##export CC

RANLIB_NEEDED = true
AR_OPTIONS = rlu

IDIR = -I$(PWD)/w -I$(PWD)/w/wh -I$(PWD)/w/w2 -I$(PWD)/w/whooks \
       -I$(PWD)/fpp -I$(PWD)/clam -I$(PWD)/file -I$(PWD)/mtp -I$(PWD)/bss -I$(PWD)/seq

########### LINUX STUFF ##############

LOCAL_LIBS = local_libs/$(ACEDB_MACHINE)

Xt_LIBS = -lX11 -L./$(LOCAL_LIBS) -L/usr/X11/lib -L/usr/X11R6/lib \
         `pkg-config --libs glib-2.0 gtk+-2.0 `  


GRAPH_DIR= w/bin.$(ACEDB_MACHINE)/
ACE_LIBS = $(GRAPH_DIR)/libgex.a $(GRAPH_DIR)/libgraph.a  $(GRAPH_DIR)/libfree.a  $(GRAPH_DIR)/libgd.a

FPC_LIBS=$(ACE_LIBS) $(Xt_LIBS) -lpthread -lm -lrt

ifeq ($(ACEDB_MACHINE),LINUX_4)
FPC_LIBS=$(ACE_LIBS) $(Xt_LIBS) -lpthread -lgdbm
endif

ifeq ($(ACEDB_MACHINE),DARWIN))
FPC_LIBS=$(ACE_LIBS) $(Xt_LIBS) -lpthread 
endif


ARCHIVES=clam/clam.a fpp/fpp.a file/file.a mtp/mtp.a bss/bss.a seq/seq.a


FPC_OBJS=bin/fpp3main.o
FPCD_OBJS=clam/parallel/fpp3nomain.o clam/parallel/fpcd.o


#################################################################
########## Machine dependent compiler modification ##############
#################################################################

include w/wmake/$(ACEDB_MACHINE)_DEF

all: 	w_all file_all clam_all fpp_all mtp_all bss_all seq_all bin/fpc

parallel:
	echo 'Remove all .o's from clam.a with PARALLEL in them'
	cd clam && ar -d clam.a `grep -l PARALLEL *.c | sed 's/.c$/.o/'`
	cd clam/parallel && ar -d clam.a `grep -l PARALLEL *.c | sed 's/.c$/.o/'`

w_all:
	-test ! -d bin && mkdir bin
	CC="$(CC)" && export CC && \
	cd w && $(MAKE) all

file_all:
	CC="$(CC)" && export CC && \
	cd file && $(MAKE) all

clam_all:
	CC="$(CC)" export CC && MODE="$(MODE)" export MODE && \
	cd clam && $(MAKE) all

fpp_all:
	CC="$(CC)" && export CC && \
	cd fpp && $(MAKE) all

mtp_all:
	CC="$(CC)" && export CC && \
	cd mtp && $(MAKE) all

bss_all:
	CC="$(CC)" && export CC && \
	cd bss && $(MAKE) all


seq_all:
	CC="$(CC)" && export CC && \
	cd seq && $(MAKE) all

clean:	w_clean file_clean clam_clean fpp_clean mtp_clean bss_clean seq_clean
	rm -f bin/fpc bin/fpp3main.o bin/fpp3nomain.o bin/fpcd clam/parallel/*.o

w_clean:
	cd w && $(MAKE) clean

file_clean:
	MODE="$(MODE)" export MODE && \
	cd clam && $(MAKE) clean

clam_clean:
	cd file && $(MAKE) clean

fpp_clean:
	cd fpp && $(MAKE) clean

mtp_clean:
	cd mtp && $(MAKE) clean

bss_clean:
	cd bss && $(MAKE) clean

seq_clean:
	cd seq && $(MAKE) clean


bin/fpc: $(ARCHIVES) $(FPC_OBJS) $(ACE_LIBS)
	$(COMPILER) $(FPC_OBJS) $(ARCHIVES) $(FPC_LIBS) -o $@

bin/fpp3main.o:	fpp/fpp3.c
	cd fpp && $(CC) -c fpp3.c -o ../$@

bin/fpcd: $(ARCHIVES) $(FPCD_OBJS) $(ACE_LIBS)
	$(COMPILER) -o $@ $(FPCD_OBJS) $(ARCHIVES) $(FPC_LIBS)

parallel/fpcd.o: clam/parallel/fpcd.c
	$(CC) -c clam/parallel/fpcd.c -o $@


clam/parallel/fpp3nomain.o: fpp/fpp3.c
	cd fpp && $(CC) -DOMIT_MAIN -c fpp3.c -o ../$@
